package cn.iocoder.yudao.framework.weixin;

import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.cp.bean.message.WxCpTpXmlMessage;
import me.chanjar.weixin.cp.config.impl.WxCpTpDefaultConfigImpl;
import me.chanjar.weixin.cp.tp.service.impl.WxCpTpServiceImpl;

/**
 * @Author: lvliangjun
 * @Date: 2024/5/22 18:34
 */
public class 解析出扫码授权AuthCode {


    //服务商的
    static String providercorpid = "ww00b36ed5acf38dc9";
    static String providerSecret = "gFjBpLXZcwSYCdI6hq2bMxBnlw-v1Xkk0WbTJJVhAAZ1soHfXgF0Owpi-yKl9AgD";

    //模板的
    static String Token = "TPJ4Fdrpasg4R";
    static String encodingAESKey = "msJgW0YBhnDkKQnGz8gtdSFnSarTSIxztBXWxicDPBR";
    //模板ID：dk83899bb2c060ce44
    //模板Secret：iK3sD1n5ovlRTDOl424mu5uGKO_VgXS5oa7V2Yf9UMA
    static String corpid = "dk83899bb2c060ce44";
    static String secret = "iK3sD1n5ovlRTDOl424mu5uGKO_VgXS5oa7V2Yf9UMA";
    public static void main(String[] args) throws WxErrorException {
        String xml = "<xml><ToUserName><![CDATA[dk83899bb2c060ce44]]></ToUserName><Encrypt><![CDATA[m9KCyZWWVM3rh4JETIT0LB3DwQnaX7QlmkWraHJrebNu6VvgO1vbvT95YnOFuvSjdflno3E2U7gIbaC50pAwteGLsdVrzGihgkTGMCedZ1vMHzyTCwTfhHy1pFbEWnE5F8d7veIVLXqSY51AHq4FAHB8OIpjIhfvEtFYjBdzoc5XWXG8xc0GDf9TscGP3vqPtBmxKOUx5uPUvBTRTuQwH02EjHuPB75KZfoEUhSRmliI4mHDe5txqcivBXpS1Rl8fXqJN5uR665ggAC5Zt7QV+HFB3jegh77d3jkh1LuHrYdtKGkEPtedQIm4tyY1Ccl+ABy5WBaT0nh95kT13HJ0AlW+efTZjEhf62DkjaFHAipOSY5kJibjnJNtWWHy1uxFdeB8kz0CAIuk0qerOyiux4rV5t8pK36nM7wZfujwXLWYZQo84N5IE8cCgRXT1I8p5eBQF1N2eSWhpiIhaEvOg==]]></Encrypt><AgentID><![CDATA[]]></AgentID></xml>";

         String timestamp="1716378723";
         String nonce="1716156716";
         String msgSignature="d39cedec36edccf22f4b86d2a4e31ab0757b2c43";

        WxCpTpServiceImpl baseWxCpService = new WxCpTpServiceImpl();
        WxCpTpDefaultConfigImpl wxCpTpConfigStorage = new WxCpTpDefaultConfigImpl();
        wxCpTpConfigStorage.setCorpId(corpid);
        wxCpTpConfigStorage.setCorpSecret(secret);
        wxCpTpConfigStorage.setToken(Token);
        wxCpTpConfigStorage.setAesKey(encodingAESKey);

        baseWxCpService.setWxCpTpConfigStorage(wxCpTpConfigStorage);



        WxCpTpXmlMessage inMessage = WxCpTpXmlMessage.fromEncryptedXml(xml, baseWxCpService.getWxCpTpConfigStorage(), timestamp, nonce, msgSignature);
        System.out.println(inMessage);

    }

}
